<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // return需要写在函数里面
    let sum = 0;
    function calc() {
      for (let index = 0; index < 5; index++) {
        // const element = array[index];
        // 0, 1, 2, 3
        sum += index;

        if (index === 3) {
          return;
        }
      }

      // console.log('123123');
    }

    calc();

    console.log(sum); // 6
  </script>
</body>

</html>